home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
The World of Computer Software.iso
/
spectr20.zip
/
SPEC2.DOC
< prev
next >
Wrap
INI File
|
1992-04-29
|
32KB
|
630 lines
[WS 1 in]
SPECTRUM CALCULATION ROUTINE
Version 2.0
[WS 4 in]
David E. Hess
Fluid Flow Group
Process Measurements Division
Chemical Science and Technology Laboratory
National Institute of Standards and Technology
Email: HESS@ENH.NIST.GOV
Phone: (301) 975-5937
[WS 0.5 in]
[April 1992]
▒New Features
* Two additional window functions are available for tapering the data.
The first, referred to as the Minimum Sidelobe window, has a maximum
sidelobe level of -93 dB; the sidelobes then decay at a rate of 18
dB/octave. The second window, the Maximum Decay window, has a maximum
sidelobe level of -61 dB, but these sidelobes decay at a rate of 42
dB/octave.
* The structure of the data files to be processed has been modified to
allow inclusion of information about the voltage transformation factor
for each channel of data. The file format has been changed to BINARY
in order to permit these data files to be written by programming
languages other than FORTRAN.
* Memory for data arrays is now allocated dynamically at run-time, and
only the memory needed for the current file being processed is
allocated at any particular time. Storage for these arrays can be
quite large and dynamic allocation of memory reduces the amount of
storage required within the SPECTRUM executable file. This
modification has reduced the size of the executable file by 75%.
* All internal temporary files created by the SPECTRUM routine are now
written in BINARY format. This saves an additional small amount of
memory at run-time.
* When an input data file consisted of only one channel of data to be
processed, the first version of SPECTRUM required that this data file
have an even number of records. This restriction has been removed.
* The manual included with the first version of SPECTRUM provides a
detailed account of the manner in which the amount of space on the
hard disk (or Ram disk) required by the routine for storage of
temporary files may be estimated. Version 2 of SPECTRUM now
calculates at run-time the amount of temporary space required to
process the current file, and then checks the hard disk (or Ram disk)
to determine if that space is available.
* The code has been restructured by removing portions of the code from
the Main module and placing these segments into functions or
subroutines. The subsequent reduction in size of the Main module has
permitted additional optimization procedures contained within the
Microsoft Fortran Optimizing Compiler, V 5.1 to be employed. Also,
the code for the Main module is now more readable.
* All of the utility files included on the diskette have been modified
to use the new input data file format. Each of these routines should
be used only with SPECTRUM V 2.0.
* The SPECTRUM routine requires a computer equipped with an 80286 or
better microprocessor. An 80287 or better numeric coprocessor is
recommended but is no longer required.
All information contained within this document supersedes the information
contained within the manual which refers to version 1.0 of the SPECTRUM
routine. Any information found in the manual which is not countermanded by
statements made here is considered to still apply.
▒Diskette Contents
The following files are contained on the diskette.
SPECTRUM FOR 66165 04-22-92 8:16a Main program source code.
SPECTRUM FI 1852 04-22-92 7:59a Interface statements.
SPECTRUM FN 2406 04-22-92 8:04a Data declaration & common areas.
SPECTRUM CFG 1197 04-23-92 3:50p Optional setup file.
SPECTRUM EXE 111592 04-23-92 3:03p Works with or w/o a coprocessor.
SPEC387 EXE 103800 04-23-92 2:43p Works only with a coprocessor.
COLOR FOR 8314 04-22-92 8:05a Source for noise generator.
COLOR EXE 57452 04-23-92 3:07p Executable for noise generator.
COLOR2 FOR 9073 04-23-92 3:13p Source for 2-chan noise gen.
COLOR2 EXE 57872 04-23-92 3:13p Executable for 2-chan noise gen.
SINE FOR 4371 04-22-92 8:06a Source for sinewave generator.
SINE EXE 50490 04-23-92 3:09p Executable for sinewave gen.
MAKDAT FOR 8960 04-22-92 8:06a Ascii to Binary converter
MAKDAT EXE 51564 04-23-92 3:11p source.
MAKCOEF FOR 6296 04-22-92 8:07a Asc to Bin converter executable.
MAKCOEF EXE 44388 04-23-92 3:11p Coefficient file creation
README 1ST 1594 04-28-92 2:54p source.
Coeff. file creation executable.
Cover letter.
The README.1ST file is simply a reminder that this is the second version
of SPECTRUM and that an update to the manual exists and should be read prior to
the first use of the program. All files with an .FOR, .FI or .FN extension are
Ascii files containing FORTRAN source code for the respective program. These
files are not required when using SPECTRUM and need not be kept on the hard
disk. If the SPECTRUM routine is recompiled, then three files are required
during compilation: SPECTRUM.FOR, SPECTRUM.FI and SPECTRUM.FN. The SPECTRUM.FI
file contains interface statements for the functions and subroutines used in
SPECTRUM, and the SPECTRUM.FN file contains data declaration statements and
COMMON statements which permit data areas to be shared by both the Main module
and other program modules. These two files are compiled along with the main
program file using the INCLUDE statement in appropriate locations in the main
program source code. This program was compiled using the Microsoft FORTRAN
Optimizing Compiler, V 5.1. The command used to compile the code and to
generate the SPECTRUM.EXE file, which may be used with or without a
coprocessor, is given by
FL /G2 /W2 /FPi SPECTRUM.FOR
In addition, an executable version of SPECTRUM has been provided which will
work only with a numeric coprocessor installed (80287, 80387 or 80486). This
executable version is called SPEC387.EXE and consists of more streamlined code
which executes somewhat faster. This version was compiled using the command
FL /G2 /W2 /FPi87 SPECTRUM.FOR
The use of the SPECTRUM.CFG file is optional and is described in the manual
which accompanied version 1 of SPECTRUM. The COLOR, COLOR2 and SINE utility
routines generate data with known spectral densities; the data files produced
by these routines are compatible with SPECTRUM and may be used for testing the
operation of the program. The use of these utility routines is reviewed in
detail in the version 1 manual. Finally, the MAKDAT and MAKCOEF routines are
used to convert Ascii data files into the BINARY data files required by the
SPECTRUM routine. These utilities are also explained in the version 1 manual.
▒Additional Windows
Two additional window functions for tapering the input data are available
in SPECTRUM V 2.0. These windows have been added as possible alternatives to
the more commonly used windows made available in V 1.0. The choice of a window
function depends upon such factors as the highest sidelobe level (dB), the rate
of decay of the sidelobes (dB/octave) and the halfwidth of the mainlobe (f T).
In general, as the width of the mainlobe is decreased, thereby increasing the
resolving power, the amplitude of the sidelobes is increased which intensifies
the problem of leakage. In many cases it is useful to allow the width of the
mainlobe to increase somewhat in order to decrease the height of the sidelobes
and / or to reduce the rate of decrease in the sidelobe level.
With this end in mind, two windows were selected from Nuttall (1981) which
are highly optimized members of a family of windows discussed by Harris
(1978). The first window, which will be denoted here as the Minimum Sidelobe
window, is the 4-term Blackman window with continuous first derivative. This
window minimizes the maximum height of the sidelobes and also has a reasonably
good rate of decay of the sidelobes at the expense of a widened mainlobe. The
second window will be referred to here as the Maximum Decay window; this is the
4-term Blackman window with continuous fifth derivative which maximizes the
rate of decay of the sidelobes and which also has a low maximum sidelobe
amplitude. As expected, the mainlobe for this window is also wider than any of
the windows contained in the first version.
These windows are defined by
[EQN "center #^ w (t) #3#3 = #3#3 #( { #3#3 stack left [[ a sub 0 #3#3 - #3#3 a
where the coefficients for the Minimum Sidelobe window are given by
[EQN "center a sub 0 #3#3 = #3#3 0.355768 #4#4 a sub 1 #3#3 = #3#3 0.487396 #4#4
and those for the Maximum Decay window by
[EQN "center a sub 0 #3#3 = #3#3 10 over 32 #4#4 a sub 1 #3#3 = #3#3 15 over 32
These functions are plotted in figure 1 with the Hanning window shown for
comparison. Notice that the Hanning window is a member of this family of
windows where the first two coefficients are 1/2 and the remaining coefficients
are zero.[PB]
The Fourier transforms for these windows are found to be
[EQN "center W #1 (f,T) #3#3 = #3#3 { #3#3 a sub 0 #3#3 #[ [sin #3 pi f T] over
where [EQN "f sub 1 #3 = #3 1 #1 / #1 T"] . The moduli of the Fourier
transforms for each of the above windows as well as for the Hanning window,
shown for comparison, are plotted in figures 2, 3 and 4. In order to clearly
reveal the maximum sidelobe height and the rate of decay of these sidelobes,
the vertical axes of the plots are magnified by using a logarithmic scale; the
power response of the windows normalized by the peak response at
[EQN "f #3 = #3 0"] and converted to decibels is defined by
[EQN "center #R[dB] #3#3 = #3#3 10 #3 #R[log] #3 [| W(f) #1 / #1 W(0)|] super 2"
The plots clearly show the optimal features for each window function. A list
of the performance parameters for all of the windows contained within SPECTRUM
is included below for completeness.
Maximum Maximum Halfwidth of
Window Sidelobe Decay Mainlobe
Type (dB) (dB/octave) (f T)
Square -13 6 1.0
Tukey -13 18 1.1
Hanning -31 18 2.0
Parzen -27 12 2.0
Welch -21 12 1.4
Min. Sidelobe -93 18 4.0
Max. Decay -61 42 4.0
Table 1 Window performance parameters
[PIC FIG1.CGM]
Figure 1 Additional window functions for tapering the data
[WS 0.5 in]
[PIC FIG2.CGM]
Figure 2 Power response for Hanning window[PB]
[PIC FIG3.CGM]
Figure 3 Power response for minimum sidelobe window
[WS 0.5 in]
[PIC FIG4.CGM]
Figure 4 Power response for maximum decay window
Input Data File Structure
The author has obtained a new A/D converter which has the capability of
altering the input voltage range to be digitized. The selection of an input
voltage range may be made via software as opposed to changing jumpers on the
board itself. After data has been sampled by the A/D converter, the author
has, in the past, written certain information to the first record of each data
file which describes the digitized information that follows. With the added
capability offered by the new A/D converter, it was felt that the input voltage
range used by each channel in the input data file would be prudent pieces of
information to add to the file header. The A/D converter has the ability to
convert up to eight differential inputs sequentially, and each channel may use
a different input voltage range. Therefore, data files from this A/D converter
may contain up to eight channels of digitized information, and the second
record of the data file is now used to record the input voltage range used by
each channel. These input data files are then used by a variety of routines
written by the author to perform various aspects of random data analysis. The
SPECTRUM program is just one member of this family of routines. Since the
SPECTRUM program can only process one or two channels of data, placing
information on the voltage range used by up to eight channels of data leads to
unnecessary information being included for six channels which do not exist. As
silly as this may seem, it turns out to be useful for the author to adopt a
single universal input data file structure which can then be used by all of the
routines which examine this data file. Therefore, this input data file
structure, while not optimal for the SPECTRUM program, is the most useful
universal setup for the author at this time.
All input data files must be sequential BINARY files. These files contain
no internal formatting information, and thus, are the most useful type of files
to use when dealing with large quantities of data. Sequential unformatted
FORTRAN data files were used as the file type for input data files in the first
version of SPECTRUM. The drawback with unformatted FORTRAN data files is that
they may be written only by FORTRAN programs. Using BINARY data files allows
the data to be written using other programming languages. Furthermore,
unformatted FORTRAN data files do, in fact, use a small amount of internal
formatting information, whereas BINARY files do not. Thus, BINARY data files
are slightly smaller than unformatted FORTRAN data files. The first two
records of the data file contain descriptive information about the digitized
data to follow and form the file header. Following the file header is the
actual digitized data. The first record of the file header is changed only
slightly from version 1.0 of the SPECTRUM routine, and the text describing this
first record is taken from the manual issued with the first version. Changes
are noted in boldface text as required.
The first record of the data file consists of a header containing four
quantities which characterize the data which follows. The first quantity is a
2-byte integer which gives the number of channels of data per record (1 or 2).
The next number is the record size in bytes and must be a 4-byte integer. The
record size is twice the number of points per record if the data consists of
2-byte integer values, or the record size is four times the number of points
per record if the data consists of 4-byte real data. The third quantity is a
2-byte integer which gives the number of records of data which follow, and the
last quantity is the time interval in microseconds between data points of the
same channel expressed as a 4-byte integer. Recall that the largest positive
signed number that may be stored as a 2-byte integer is 32,767 and, for a
4-byte integer, the value is 2,147,483,647.
For example, suppose the data file consists of 100 records of one channel
of data saved as 2-byte integers and sampled at 10000 samples per second with
2048 data points per record. The first record of the data file would contain
the four values:
[EQN "center 1 #4#4 4096 #4#4 100 #4#4 100 #4#4"]
Now suppose that two channels of data were sampled with a time interval of
0.016383 seconds between each successive data point resulting in a time
interval of 0.032766 seconds between each successive data point of the same
channel. Furthermore, 40 records of data were sampled with 8192 data points
per record such that each channel of data consisted of 4096 data points.
Finally, the data were transformed into desired quantities and saved as 4-byte
floating-point numbers. The first record for this data file should consist of
the following four numbers:
[EQN "center 2 #4#4 32768 #4#4 40 #4#4 32766"]
The second record of the data file consists of eight 2-byte integer values
which encode the input voltage range used by channels 1 to 8. Acceptable
values are
[EQN "center matrix [[[# ] [# ] [# ] [# ] [# ] [# ] [#R[Value]] [# ] [#R[Range]]
The user should write a 2-byte integer value from 0 to 3 to indicate the
voltage range used by the first channel and the second channel. Six additional
zero values must be entered for channels 3 through 8 which are not used by the
SPECTRUM routine. For example, to indicate that the input voltage range for
the first channel was -5V to 5V and for the second channel was -1.25V to 1.25V,
the user would write the following to the second record of the data file.
[EQN "center 1 #3#3 3 #3#3 0 #3#3 0 #3#3 0 #3#3 0 #3#3 0 #3#3 0 #3#3"]
When the SPECTRUM program is run, the routine will ask if an alternate voltage
transformation factor should be used. If the user responds with yes, then the
user must type in the voltage per digital level conversion factor to be used
for that channel, and this factor will be used in place of the factor stored in
record 2 of the data file. After reading in the data file, the SPECTRUM
routine will convert the digitized data back into voltages using the conversion
factors shown above. If none of the above voltage ranges are appropriate for a
particular data file, then the user should proceed as follows. Store eight
zero values (2-byte integers) on the second record of the data file. Then,
execute the SPECTRUM routine and enter the appropriate alternate conversion
factor when requested.
Following the first two records containing the file header is the actual
data. When the data comes directly from an analog to digital converter
(12-bit, say), then the values range from -2048 to 2047 (or 0 to 4095) and are
appropriately stored as 2-byte integers. Alternatively, if some preprocessing
is typically performed on the data, the data may be stored as 4-byte
floating-point numbers. As a result of the Fast Fourier Transform (FFT)
algorithm used in this routine, the number of data points per channel per
record must be a power of 2.
In the first version of SPECTRUM, the program required an even number of
records of data in the input data file when the file consisted of one channel
of sampled data. This is no longer required. When the program submits the
data to the FFT module to be transformed, two records are submitted to the FFT
algorithm to be transformed simultaneously as a time-saving measure. If an odd
number of records is detected in the input data file in the case of one channel
of data, then the program automatically appends an additional record of data
containing a copy of the data values of the previous record. After
transformation, the results of the added record are discarded so that the
output is not corrupted by the internal addition of a record of data. When two
channels of data are sampled, an even or odd number of records is not a factor
because one record from each channel is submitted to the FFT module for
simultaneous transformation.
One or two separate time series (channels) may be stored per record. The
method of storing the data values in each record follows the standard procedure
used by analog to digital converters:
[EQN "center #R[one] #4 #R[channel] #^ #R[:] #4#4 x sub 0 #3 x sub 1 #3 x sub 2
where the notation is as defined above. This convention must be followed even
if the data are processed and then stored as floating-point numbers. When two
channels of data are sampled and then stored to a data file, the values for
each channel of data should be of the same data type: either 2-byte integers or
4-byte floating-point numbers. If the user is unfamiliar with the task of
creating BINARY data files, then the user may instead create these files in an
ASCII file format. A utility MAKDAT which is included on the diskette can then
be used to write the file header and transform the ASCII data files into the
BINARY data files required by the spectrum routine. See the section on utility
files in the manual included with version 1.0.
This section gives a few lines of code which are representative of the
manner in which these data files are written and read. When writing, the file
is first opened, the file header is written, the data is written and then the
file is closed.
INTEGER*2 ICHANS, NUMREC
INTEGER*4 IRSIZE, IDELTMS, N, I
INTEGER*2 NDATA (NMAX), GAIN (0 : 7)
OPEN (2, FILE = 'A001.DAT', STATUS = 'UNKNOWN',
ACCESS = 'SEQUENTIAL', FORM = 'BINARY')
WRITE (2) ICHANS, IRSIZE, NUMREC, IDELTMS
WRITE (2) (GAIN (I), I = 0, 7)
DO J = 1, NUMREC
... put data record into NDATA array ...
WRITE (2) (NDATA (I), I = 1, N)
... get next record of data ...
ENDDO
CLOSE (2, STATUS = 'KEEP')
The same procedure is followed when the data file is opened and read by
the spectrum routine. The file is opened, the file header is read, the data is
read and then the file is closed.
INTEGER*2 ICHANS, NUMREC
INTEGER*4 IRSIZE, IDELTMS, N, I
INTEGER*2 NDATA (NMAX), GAIN (0 : 7)
OPEN (2, FILE = 'A001.DAT', STATUS = 'OLD',
ACCESS = 'SEQUENTIAL', FORM = 'BINARY')
READ (2) ICHANS, IRSIZE, NUMREC, IDELTMS
READ (2) (GAIN (I), I = 0, 7)
N = IRSIZE/2
DELT = FLOAT (IDELTMS) / 1000000.0
DO J = 1, NUMREC
READ (2) (NDATA (I), I = 1, N)
... process this record of data ...
ENDDO
CLOSE (2, STATUS = 'KEEP')
MAKCOEF Utility Routine
The use of this utility routine for the generation of coefficient data
files for use with SPECTRUM is essentially the same. The output of the program
is now a BINARY coefficient data file vis a vis the unformatted FORTRAN
coefficient data file generated in the first version. The SPECTRUM routine now
allocates memory dynamically for all internal arrays at run-time. This
improvement in the main program has unfortunately introduced an additional
restriction on the generation of coefficient data files. The first set of
coefficients contained in the coefficient data file must correspond to the
first file to be processed by SPECTRUM, and the last set of coefficients
contained in the coefficient data file must correspond to the last file to be
processed by SPECTRUM. The total number of sets of coefficients contained in
the coefficient data file should be given by
[EQN "center #R[numsets] #3#3 = #3#3 #R[last] #3#3 - #3#3 #R[first] #3#3 + #3#3
The total number of files processed by SPECTRUM need not match the total number
of sets of coefficients contained in the coefficient data file as long as the
first and last sets of coefficients correspond to the first and last files
processed, and the remainder of the files to be processed correspond to sets of
coefficients that are contained between the first and last sets in the
coefficient data file. This restriction will be clarified below using the
example given on pp 70-71 from the manual included with the first version.
Suppose that it was desired to process the data files D061.DAT thru
D086.DAT in a batch by the spectrum routine. Each of these data files
consisted of two channels of 2-byte integers taken from an experiment in fluid
mechanics, say. Furthermore, suppose that the quantities sampled were two
components of a fluid velocity, which were transduced into voltages by some
means and then sampled by an A/D converter. The user knows the calibration
data for the transducer, and the required transformation from voltages back
into velocities can be accomplished for each velocity component by using a
polynomial of up to fourth degree in the form:
[EQN "center u sub n #3#3 = #3#3 b sub 0 #3 + #3 b sub 1 v sub n #3 + #3 b sub 2
where [EQN "v sub n"] is the nth data point expressed as a voltage,
[EQN "b sub 0 #1 , #3 b sub 1 #1 , ... , b sub 4"] are the coefficients of the
velocity transformation and [EQN "u sub n"] is the nth data point which has
been converted to a velocity. Now, suppose further that the data in each of
the files were taken over a period of time in which the calibration
coefficients changed; thus, a different set of coefficients are required for
each of the 26 files to be processed. Following the instructions in the
section on coefficient data files, this scenario would require the creation of
two BINARY coefficient data files, DCON.DAT and DCON2.DAT, each containing the
26 sets of five coefficients [EQN "b sub 0 #1 , #3 b sub 1 #1 , ... , b sub 4"]
for the velocity transformation for channel 1 and channel 2, respectively.
The user should create each ASCII data file with a four character name
followed by the extension [.ASC]. The names should conform to the various
naming conventions specified earlier. The ASCII file must contain numbers
only, although blank lines may be inserted into the file if desired. The
numbers will be transferred to 4-byte floating point quantities in the
unformatted data file thereby limiting the coefficients to single precision (6
or 7 decimal places). The coefficients may be stored one per line or many per
line in the ASCII file. The first number in the file will be [EQN "b sub 0"]
for channel 1 of data file D061.DAT; the fifth number in the file should be
[EQN "b sub 4"] for channel 1 of data file D061.DAT; the sixth number in the
file will be [EQN "b sub 0"] for channel 1 of data file D062.DAT, and so on.
The 130th and last number in the file should be [EQN "b sub 4"] for channel 1
of data file D086.DAT. The user should then create a second ASCII file in a
similar manner specifying all of the coefficients for channel 2 of the 26 files
to be processed. The utility MAKCOEF should then be executed twice, first
transferring the contents of the first ASCII file (for channel 1) to DCON.DAT
and then for the second ASCII file (for channel 2) to DCON2.DAT. A session
using MAKCOEF would proceed as follows.
makcoef
Enter first letter of data file to
which these coefficients will be associated : d
Are these coefficients for channel (1 or 2) : 1
Enter # of sets of coefficients : 26
Enter starting file number : 61
Enter ASCII input file name (4 chars) : chn1
C O E F F I C I E N T F I L E C R E A T I O N U T I L I T Y
Creating DCON.DAT now.
# sets of coeffs = 26
# coeffs in each set = 5
# of starting file = 61
Program terminated successfully.
The MAKCOEF routine will read the ASCII file CHN1.ASC and will write the
following file header to the BINARY file DCON.DAT:
[EQN "center 26 #4#4 61"]
The coefficients for channel 1 are then transferred to the BINARY file. Note
that 5 coefficients per set are required; therefore, this number is not written
to the file header. If, at a later time, the user wishes to reprocess the
files D074.DAT through D080.DAT (perhaps specifying different options in the
spectrum routine), it is necessary to re-create the two coefficient data files;
the new data files will contain 7 sets of coefficients beginning with those
corresponding to D074.DAT and ending with those corresponding to D080.DAT. If
the user wishes to process the data files in an arbitrarily numbered order (not
consecutively), the coefficient data files may need to be changed. For
example, if the files D064.DAT, D069.DAT and D086.DAT were to be processed by
SPECTRUM, this would necessitate a change in the coefficient data files
requiring 23 sets of coefficients in each file: the first set corresponding to
D064.DAT and the last set to D086.DAT. On the other hand, the files D061.DAT,
D064.DAT, D069.DAT and D086.DAT could be processed by SPECTRUM without changing
the coefficient data files since the first and last files correspond to the
first and last sets of coefficients. The converse is also true, however. If
the user desires at the outset to process only the four arbitrarily ordered
files in the latter case above, two coefficient data files must be created
which contain not 4, but 26 sets of 5 coefficients for the data files D061.DAT
through D086.DAT. The spectrum routine requires that sets of coefficients in
the coefficient data file be listed for consecutively numbered files even if
not all of the sets of coefficients are used. With this in mind, it is perhaps
best to store all of the coefficients for an entire set of input data files in
a master ASCII file; then members of the set can be processed by the spectrum
routine either consecutively or in an arbitrarily numbered order at any
subsequent time and the BINARY coefficient data files can be easily created by
editing the master ASCII file and using MAKCOEF. Of course, the user could
transform the voltages back into dimensional quantities using his/her own code
and store the resulting floating-point numbers into ASCII data files (then use
MAKDAT) or directly into BINARY data files to be processed by SPECTRUM; then,
all of this mess concerning coefficient data files could be avoided altogether.
*References
Harris, F.J. 1978 On the use of windows for harmonic analysis with the discrete
Fourier transform, Proceedings of the IEEE, 66, 51-83.
Nuttall, A.H. 1981 Some windows with very good sidelobe behavior, IEEE
Transactions on Acoustics, Speech and Signal Processing, ASSP-29, 84-91.